package com.after.saas.client.service.factory;

import com.after.saas.client.service.RemoteUserService;
import com.after.saas.common.constants.Result;
import com.after.saas.common.model.bo.UserBO;
import com.after.saas.common.model.query.UserQuery;
import com.after.saas.common.model.vo.UserVO;
import com.after.saas.common.utils.ResponseUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * @Classname RemoteUserServiceImpl
 * @Description TODO
 * @auth after
 * @since 2021/7/20 20:29
 */

@Component
public class UserServiceHystrixFactory implements FallbackFactory<RemoteUserService> {


    @Override
    public RemoteUserService create(Throwable cause) {
        return new RemoteUserService() {
            @Override
            public Result<Boolean> batchSave(List<UserBO> userBOS) {
                return ResponseUtil.FAILURE("批量保存失败！" + cause.getMessage(), false);
            }

            @Override
            public Result findOne(UserQuery query) {
                return ResponseUtil.FAILURE("用户查询失败！" + cause.getMessage());
            }

            @Override
            public Result<Page<UserVO>> queryByPage(UserQuery query) {
                return ResponseUtil.FAILURE("用户查询失败！" + cause.getMessage());
            }

            @Override
            public Result<List<UserVO>> list(UserQuery query) {
                return ResponseUtil.FAILURE("用户查询失败！" + cause.getMessage());
            }

            @Override
            public Result<UserVO> findById(Long id) {
                return ResponseUtil.FAILURE("用户查询失败！" + cause.getMessage());
            }
        };
    }
}
